/**
 * Copyright (c) 2010 Simple Graph Tools contributors. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * $Id$
 */
package org.sgt.coredef.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.sgt.coredef.Chain;
import org.sgt.coredef.Condition;
import org.sgt.coredef.ConstrainedObject;
import org.sgt.coredef.Constraint;
import org.sgt.coredef.CoredefPackage;
import org.sgt.coredef.Edge;
import org.sgt.coredef.Node;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Chain</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.sgt.coredef.impl.ChainImpl#getPreConditions <em>Pre Conditions</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ChainImpl#getPostConditions <em>Post Conditions</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ChainImpl#getConstraints <em>Constraints</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ChainImpl#getEdges <em>Edges</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ChainImpl#getNodes <em>Nodes</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ChainImpl#getStartNode <em>Start Node</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ChainImpl#getEndNode <em>End Node</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ChainImpl extends EObjectImpl implements Chain {
	/**
	 * The cached value of the '{@link #getPreConditions() <em>Pre Conditions</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPreConditions()
	 * @generated
	 * @ordered
	 */
	protected EList<Condition> preConditions;

	/**
	 * The cached value of the '{@link #getPostConditions() <em>Post Conditions</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPostConditions()
	 * @generated
	 * @ordered
	 */
	protected EList<Condition> postConditions;

	/**
	 * The cached value of the '{@link #getConstraints() <em>Constraints</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getConstraints()
	 * @generated
	 * @ordered
	 */
	protected EList<Constraint> constraints;

	/**
	 * The cached value of the '{@link #getEdges() <em>Edges</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEdges()
	 * @generated
	 * @ordered
	 */
	protected EList<Edge> edges;

	/**
	 * The cached value of the '{@link #getNodes() <em>Nodes</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNodes()
	 * @generated
	 * @ordered
	 */
	protected EList<Node> nodes;

	/**
	 * The cached value of the '{@link #getStartNode() <em>Start Node</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartNode()
	 * @generated
	 * @ordered
	 */
	protected Node startNode;

	/**
	 * The cached value of the '{@link #getEndNode() <em>End Node</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndNode()
	 * @generated
	 * @ordered
	 */
	protected Node endNode;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ChainImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CoredefPackage.Literals.CHAIN;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Condition> getPreConditions() {
		if (preConditions == null) {
			preConditions = new EObjectResolvingEList<Condition>(Condition.class, this, CoredefPackage.CHAIN__PRE_CONDITIONS);
		}
		return preConditions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Condition> getPostConditions() {
		if (postConditions == null) {
			postConditions = new EObjectResolvingEList<Condition>(Condition.class, this, CoredefPackage.CHAIN__POST_CONDITIONS);
		}
		return postConditions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Constraint> getConstraints() {
		if (constraints == null) {
			constraints = new EObjectResolvingEList<Constraint>(Constraint.class, this, CoredefPackage.CHAIN__CONSTRAINTS);
		}
		return constraints;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Edge> getEdges() {
		if (edges == null) {
			edges = new EObjectResolvingEList<Edge>(Edge.class, this, CoredefPackage.CHAIN__EDGES);
		}
		return edges;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Node> getNodes() {
		if (nodes == null) {
			nodes = new EObjectResolvingEList<Node>(Node.class, this, CoredefPackage.CHAIN__NODES);
		}
		return nodes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node getStartNode() {
		if (startNode != null && startNode.eIsProxy()) {
			InternalEObject oldStartNode = (InternalEObject)startNode;
			startNode = (Node)eResolveProxy(oldStartNode);
			if (startNode != oldStartNode) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CoredefPackage.CHAIN__START_NODE, oldStartNode, startNode));
			}
		}
		return startNode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node basicGetStartNode() {
		return startNode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartNode(Node newStartNode) {
		Node oldStartNode = startNode;
		startNode = newStartNode;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CoredefPackage.CHAIN__START_NODE, oldStartNode, startNode));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node getEndNode() {
		if (endNode != null && endNode.eIsProxy()) {
			InternalEObject oldEndNode = (InternalEObject)endNode;
			endNode = (Node)eResolveProxy(oldEndNode);
			if (endNode != oldEndNode) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CoredefPackage.CHAIN__END_NODE, oldEndNode, endNode));
			}
		}
		return endNode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node basicGetEndNode() {
		return endNode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEndNode(Node newEndNode) {
		Node oldEndNode = endNode;
		endNode = newEndNode;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CoredefPackage.CHAIN__END_NODE, oldEndNode, endNode));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isComplete() {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean canGrowForward(Node node) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean canGrowBackwards(Node node) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Chain copy() {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node nextNode(Node currentNode) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean appendNode(Node node, Node toNode) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node previousNode(Node node) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean prependNode(Node node, Node toNode) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isLooping() {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CoredefPackage.CHAIN__PRE_CONDITIONS:
				return getPreConditions();
			case CoredefPackage.CHAIN__POST_CONDITIONS:
				return getPostConditions();
			case CoredefPackage.CHAIN__CONSTRAINTS:
				return getConstraints();
			case CoredefPackage.CHAIN__EDGES:
				return getEdges();
			case CoredefPackage.CHAIN__NODES:
				return getNodes();
			case CoredefPackage.CHAIN__START_NODE:
				if (resolve) return getStartNode();
				return basicGetStartNode();
			case CoredefPackage.CHAIN__END_NODE:
				if (resolve) return getEndNode();
				return basicGetEndNode();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CoredefPackage.CHAIN__PRE_CONDITIONS:
				getPreConditions().clear();
				getPreConditions().addAll((Collection<? extends Condition>)newValue);
				return;
			case CoredefPackage.CHAIN__POST_CONDITIONS:
				getPostConditions().clear();
				getPostConditions().addAll((Collection<? extends Condition>)newValue);
				return;
			case CoredefPackage.CHAIN__CONSTRAINTS:
				getConstraints().clear();
				getConstraints().addAll((Collection<? extends Constraint>)newValue);
				return;
			case CoredefPackage.CHAIN__EDGES:
				getEdges().clear();
				getEdges().addAll((Collection<? extends Edge>)newValue);
				return;
			case CoredefPackage.CHAIN__NODES:
				getNodes().clear();
				getNodes().addAll((Collection<? extends Node>)newValue);
				return;
			case CoredefPackage.CHAIN__START_NODE:
				setStartNode((Node)newValue);
				return;
			case CoredefPackage.CHAIN__END_NODE:
				setEndNode((Node)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CoredefPackage.CHAIN__PRE_CONDITIONS:
				getPreConditions().clear();
				return;
			case CoredefPackage.CHAIN__POST_CONDITIONS:
				getPostConditions().clear();
				return;
			case CoredefPackage.CHAIN__CONSTRAINTS:
				getConstraints().clear();
				return;
			case CoredefPackage.CHAIN__EDGES:
				getEdges().clear();
				return;
			case CoredefPackage.CHAIN__NODES:
				getNodes().clear();
				return;
			case CoredefPackage.CHAIN__START_NODE:
				setStartNode((Node)null);
				return;
			case CoredefPackage.CHAIN__END_NODE:
				setEndNode((Node)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CoredefPackage.CHAIN__PRE_CONDITIONS:
				return preConditions != null && !preConditions.isEmpty();
			case CoredefPackage.CHAIN__POST_CONDITIONS:
				return postConditions != null && !postConditions.isEmpty();
			case CoredefPackage.CHAIN__CONSTRAINTS:
				return constraints != null && !constraints.isEmpty();
			case CoredefPackage.CHAIN__EDGES:
				return edges != null && !edges.isEmpty();
			case CoredefPackage.CHAIN__NODES:
				return nodes != null && !nodes.isEmpty();
			case CoredefPackage.CHAIN__START_NODE:
				return startNode != null;
			case CoredefPackage.CHAIN__END_NODE:
				return endNode != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
		if (baseClass == ConstrainedObject.class) {
			switch (derivedFeatureID) {
				case CoredefPackage.CHAIN__CONSTRAINTS: return CoredefPackage.CONSTRAINED_OBJECT__CONSTRAINTS;
				default: return -1;
			}
		}
		return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
		if (baseClass == ConstrainedObject.class) {
			switch (baseFeatureID) {
				case CoredefPackage.CONSTRAINED_OBJECT__CONSTRAINTS: return CoredefPackage.CHAIN__CONSTRAINTS;
				default: return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

} //ChainImpl
